from django.db import models

from models import BaseModel


# Create your models here.
# 定义导航的模型类
class Nav(BaseModel):
    # 字段选项
    # 模型对象.<字段名>  ---> 实际数据
    # 模型对象.get_<字段名>_display()  --> 文本提示
    POSITION = (
        # (实际数据, "文本提示"),
        (0, "顶部导航"),
        (1, "脚部导航"),
    )
    link=models.CharField(max_length=100,verbose_name='链接')
    is_http=models.CharField(max_length=100,verbose_name="是否是外部链接")
    position=models.IntegerField(default=0,choices=POSITION,verbose_name="导航位置")
    class Meta:
        db_table="fg_nav"
        verbose_name="导航菜单"
        verbose_name_plural=verbose_name

# 首页分类
class Category(BaseModel):
    cname=models.CharField(max_length=50,verbose_name="分类名称")
    ishot=models.IntegerField(default=0,verbose_name="是否热门")
    isgood=models.IntegerField(default=0,verbose_name="是否推荐")
    ishome=models.IntegerField(default=0,verbose_name="是否首页展示")
    parent=models.ForeignKey("self",on_delete=models.CASCADE,null=True,blank=True,
                             verbose_name="父级分类id",related_name="children")

    class Meta:
        db_table="fg_category"
        verbose_name="分类"
        verbose_name_plural=verbose_name

# 轮播图的实体
class Banner(BaseModel):
    image = models.ImageField(upload_to='banner/%Y/', verbose_name='轮播图路径')
    link = models.CharField(max_length=100, verbose_name='轮播图跳转的链接')
    is_http=models.BooleanField(default=False,verbose_name="是否是外部链接")
    note=models.CharField(max_length=100,verbose_name="备注")

    class Meta:
        db_table="fg_banner"
        verbose_name="轮播图"
        verbose_name_plural=verbose_name